#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
using std::ostream;
//输出流运算符的重载
void test(){
    string str = "hello,world";
    cout << str << endl;
}
class Complex{
public:
    Complex(int real, int image)
    :_real(real)
    ,_image(image)
    {
        cout << "Complex(int,int)" << endl;
    }

    friend ostream & operator<<(ostream & os, const Complex & c1);
private:
    int _real;
    int _image;
};
//需要将该函数声明为Complex的友元
ostream & operator<<(ostream & os, const Complex & c1){
    os << c1._real << "+" << c1._image << "i";
    return os;
}
//使用友元函数的形式
void test2(){
    Complex c1(1, 2);
    cout << c1 << endl;
}
void test3(){
    int a = 10;
    //下面这两行代码是等价的
    cout.operator<<(a).operator<<(endl);
    cout << a << endl;
}

int main()
{
    test2();

    return 0;
}

